import { globalConfig } from "../config/global";
import { createLogger } from "../core/utils/logging";
import { Vector } from "../core/utils/vector";
import { raceDefine } from "./defines/race_define";
import { People } from "./people";
import { SaveGameStorage } from "./savegame";
import { SaveGameItemStorage } from "./savegame/savegame_item";
import { SaveGamePlayerStorage } from "./savegame/savegame_player";
import { SaveGameSundryStorage } from "./savegame/savegame_sundry";
import { SaveGameWorldStorage } from "./savegame/savegame_world";

const logger = createLogger('game/game_data_craete');

/**
 * 创建游戏所有对象类
 */
export class GameDataCreate{
  constructor(generateData, cb){
    this.generateData = generateData;
    this.cb = cb;

    this.playerData = new SaveGamePlayerStorage();
    this.worldData = new SaveGameWorldStorage();
    this.itemData = new SaveGameItemStorage();
    this.sundryData = new SaveGameSundryStorage();

    this.start();
  }

  start(){
    // 创建人类
    this.createHuman();
    // 创建世界初始数据
    this.createWorld();

    this.cb({
      playerData: this.playerData,
      itemData: this.itemData,
      worldData: this.worldData,
      sundryData: this.sundryData
    });
  }

  createHuman(){
    logger.log('🌠 玩家数据创建中...');

    this.playerData.troops.push(new People(null, {
      _id: globalConfig.player._id,
      race: this.generateData.race[0],
      name: this.generateData.playerName,
      gender: this.generateData.gender[0],
      talents: this.generateData.talents,
      worldPos: [0, 0],
      mapPos: [0, 0]
    }).data);

    logger.log('🌠 玩家数据创建完毕');
  }

  createWorld(){

  }
}